<?php

namespace App\Http\Controllers\BK;

use App\Http\Controllers\Controller;
use App\Http\Requests\BK\Setting\GetUsageRequest;
use App\Http\Requests\BK\Setting\IndexKeyRequest;
use App\Http\Requests\BK\Setting\StoreKeyRequest;
use App\Http\Requests\BK\Setting\UpdateSettingRequest;
use App\Services\SettingService;
use Illuminate\Http\Request;

class SettingController extends Controller
{

    public function __construct()
    {
        $this->middleware(['auth:admins'])->except(['getUsage']);
    }
    /**
     * 更新配置项
     * @param UpdateSettingRequest $request
     * @param SettingService $settingService
     * @return \Illuminate\Http\JsonResponse
     */
    public function update(UpdateSettingRequest $request, SettingService $settingService)
    {
        return success($settingService->updateSingleSetting($request->get('key'), $request->get('value')));
    }

    /**
     * 配置项列表
     * @param Request $request
     * @param SettingService $settingService
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(SettingService $settingService)
    {
        return success($settingService->getAllSetting());
    }
}
